package com.kgc.stu.stuuserweb.controller;

import com.kgc.stu.bean.Studentinfo;
import com.kgc.stu.service.StudentinfoService;
import com.kgc.stu.stuuserweb.util.ResultEntity;
import org.apache.dubbo.config.annotation.Reference;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author shkstart
 * @create 2020-10-02 8:14
 */
@RestController
public class StudentinfoController {

    @Reference
    StudentinfoService studentinfoService;


    @RequestMapping("/select")
    public List<Studentinfo> select(){
        List<Studentinfo> studentinfos = studentinfoService.selectStudentinfo();
        return studentinfos;
    }

    @RequestMapping("/add")
    public Integer  add(@RequestBody Studentinfo studentinfo){
        Integer add;
        if(studentinfo.getSid()==null){
           add=studentinfoService.addStudentinfo(studentinfo);
        }else{
            add=studentinfoService.updateStudentinfo(studentinfo);
        }
        return add;
    }

    @RequestMapping("/selectById")
    public ResultEntity<Studentinfo> selectById(Integer sid){
        Studentinfo studentinfo = studentinfoService.selectByid(sid);
        return ResultEntity.successWithoutData(studentinfo);
    }
}
